 <table class="datatable table table-striped table-hover" id="all_users">
  <thead>
    <tr>
      <th class="hidden-xs">用户名</th>
      <th class="hidden-xs">邮箱</th>
      <th class="hidden-xs">部门</th>
      <th class="hidden-xs">权限</th>
      <th class="hidden-xs">操作</th>
    </tr>
  </thead>
  <tbody>
    <%  @users.each do |user| %>
    <tr>
      <td class="hidden-xs"><%= user.name %></td>
      <td class="hidden-xs"><%= user.email %></td>
      <td class="hidden-xs"><%= user.group.name rescue '无归属部门' %></td>
      <td class="hidden-xs"><%= user.is_admin? ? '管理员' : '普通人员' %></td>
      <td class="hidden-xs">
        <% if user.is_admin? %>
          <%= link_to '删除', user_path(user), method: :delete, class: "btn btn-xs del-btn btn-danger" %>
          <a class="set-normal-btn btn btn-xs btn-success" href="users/<%= user.id %>/be_normal">设为普通用户</a>
        <% else %>
          <%= link_to '删除', user_path(user), method: :delete, class: "btn btn-xs del-btn btn-danger" %>
          <a class="set-admin-btn btn btn-xs btn-warning" href="users/<%= user.id %>/be_admin">设为管理员</a>
        <% end %>
      </td>
    </tr>
    <% end %>
  </tbody>
  </table>
  <script>
  $('#all_users').DataTable({
    stateSave: true
  });
  $(".del-btn").click(function(event) {
    if (!confirm("你确定要删除该用户？")) {
      event.preventDefault();
      event.stopPropagation();
    }
  });
  $(".set-admin-btn").click(function(event) {
    if (!confirm("你确定要将该用户设置为管理员？")) {
      event.preventDefault();
      event.stopPropagation();
    }
  });
    $(".set-normal-btn").click(function(event) {
    if (!confirm("你确定要将该用户设置为管理员？")) {
      event.preventDefault();
      event.stopPropagation();
    }
  });
  </script>
